import React from 'react';
import {numberHandle} from '~/utils/number';
import CommonEchart from '../../../common/CommonEchart';

const precision = 2;

const tooltipCallback = (params = []) => {
    const tooltipList = params.map((chartItem, index) => {
        const {marker, name, seriesName, value} = chartItem;
        let result = '';
        if (index === 0) {
            result = `${name}<br/>${marker}${seriesName}: ${numberHandle(
                value,
                precision
            )}`;
        } else {
            result = `<br/>${marker}${seriesName}: ${numberHandle(
                value,
                precision
            )}`;
        }
        return result;
    });
    return tooltipList.join('');
};

const labelFormatter = (params = {}) => {
    const {value = ''} = params;
    return `${numberHandle(value, precision)}`;
};

const extendOptions = {
    chartId: 'MonthRefundBarChart',
    tooltip: {
        trigger: 'axis',
        formatter: tooltipCallback
    },
    dataZoom: [
        {
            type: 'inside',
        },
        {
            type: 'slider'
        }
    ],
    xAxis: {
        common: {
            axisLabel: {
                interval: 0,
                rotate: 30,
                showMinLabel: false,
                showMaxLabel: false
            }
        }
    },
    yAxis: {
        common: {
            splitLine: {show: false},
            name: '',
            axisLabel: {
                formatter: value => numberHandle(value)
            }
        }
    },
    legend: {
        // orient: 'vertical',
        left: 'left'
    },
    grid: {
        show: false,
        left: '3%',
        right: 70,
        bottom: 50,
        containLabel: true
    },
    series: {
        common: {
            stack: '总量',
            barMaxWidth: 30,
            barCategoryGap: '50%',
            // label: {show: true, position: 'top', fontSize: 10, formatter: labelFormatter},
            // emphasis: {
            //     itemStyle: {
            //         shadowBlur: 10,
            //         shadowOffsetX: 0,
            //         shadowColor: 'rgba(0, 0, 0, 0.5)'
            //     }
            // }
        }
    }
};

const MonthRefundBarChart = props => (
    <CommonEchart {...props} extendEchartsOptions={extendOptions} />
);

export default MonthRefundBarChart;
